package com.lykj.modules.shop.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;

import javax.validation.Valid;

import com.lykj.core.mp.support.Condition;
import com.lykj.core.mp.support.Query;
import com.lykj.core.tool.api.R;
import com.lykj.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lykj.modules.shop.entity.StoreCalendar;
import com.lykj.modules.shop.vo.StoreCalendarVO;
import com.lykj.modules.shop.wrapper.StoreCalendarWrapper;
import com.lykj.modules.shop.service.StoreCalendarService;
import com.lykj.core.boot.ctrl.LykjController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 红包日历记录 控制器
 *
 * @author cxl
 * @since 2022-03-29
 */
@RestController
@AllArgsConstructor
@RequestMapping("lykj-shop/store/calendar")
@Api(value = "红包日历记录", tags = "红包日历记录接口")
public class StoreCalendarController extends LykjController {

	private final StoreCalendarService storeCalendarService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入storeCalendar")
	public R<StoreCalendarVO> detail(StoreCalendar storeCalendar) {
		StoreCalendar detail = storeCalendarService.getOne(Condition.getQueryWrapper(storeCalendar));
		return R.data(StoreCalendarWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 红包日历记录
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入storeCalendar")
	public R<IPage<StoreCalendarVO>> list(@ApiIgnore @RequestParam Map<String, Object> map, Query query) {
		if(Func.isNull(query.getAscs())) {
			query.setDescs("id");
		}
		StoreCalendarVO storeCalendar = JSON.parseObject(JSON.toJSONString(map), StoreCalendarVO.class);
		IPage<StoreCalendarVO> pages = storeCalendarService.selectStoreCalendarPage(Condition.getPage(query), storeCalendar);
		return R.data(pages);
	}


	/**
	 * 自定义分页 红包日历记录
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入storeCalendar")
	public R<IPage<StoreCalendarVO>> page(StoreCalendarVO storeCalendar, Query query) {
		if(Func.isNull(query.getAscs())) {
			query.setDescs("id");
		}
		IPage<StoreCalendarVO> pages = storeCalendarService.selectStoreCalendarPage(Condition.getPage(query), storeCalendar);
		return R.data(pages);
	}

	/**
	 * 新增 红包日历记录
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入storeCalendar")
	public R save(@Valid @RequestBody StoreCalendar storeCalendar) {
		return R.status(storeCalendarService.save(storeCalendar));
	}

	/**
	 * 修改 红包日历记录
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入storeCalendar")
	public R update(@Valid @RequestBody StoreCalendar storeCalendar) {
		return R.status(storeCalendarService.updateById(storeCalendar));
	}

	/**
	 * 新增或修改 红包日历记录
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入storeCalendar")
	public R submit(@Valid @RequestBody StoreCalendar storeCalendar) {
		return R.status(storeCalendarService.saveOrUpdate(storeCalendar));
	}


	/**
	 * 删除 红包日历记录
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(storeCalendarService.deleteLogic(Func.toLongList(ids)));
	}


}
